package com.ruoyi.ly.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.ly.domain.MobileLink;
import com.ruoyi.ly.domain.dto.MobileLinkAddDTO;
import com.ruoyi.ly.domain.dto.MobileLinkUpdateDTO;
import com.ruoyi.ly.domain.dto.PageMobileLinkDTO;
import com.ruoyi.ly.domain.vo.MobileLinkVO;
import com.ruoyi.ly.domain.vo.PageMobileLinkVO;
import com.ruoyi.ly.mapper.MobileLinkMapper;
import com.ruoyi.ly.service.MobileLinkService;
import com.ruoyi.ly.utils.PageResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class MobileLinkServiceImpl implements MobileLinkService {
    
    @Autowired
    private MobileLinkMapper mobileLinkMapper;

    @Override
    public void update(MobileLinkUpdateDTO mobileLinkUpdateDto) {
        MobileLink mobileLink =new MobileLink();
        BeanUtils.copyProperties(mobileLinkUpdateDto,mobileLink);
        mobileLinkMapper.update(mobileLink);
    }

    @Override
    public void save(MobileLinkAddDTO mobileLinkAddDTO) {
        MobileLink mobileLink =new MobileLink();
        BeanUtils.copyProperties(mobileLinkAddDTO,mobileLink);
        mobileLink.setCreateTime(String.valueOf(System.currentTimeMillis()));
        mobileLinkMapper.insert(mobileLink);
    }

    @Override
    public PageResult pageQuery(PageMobileLinkDTO pageMobileLinkDTO) {
        PageHelper.startPage(pageMobileLinkDTO.getPage(), pageMobileLinkDTO.getPageSize());
        Page<PageMobileLinkVO> page = mobileLinkMapper.pageQuery(pageMobileLinkDTO);
        long total = page.getTotal();
        List<PageMobileLinkVO> records = page.getResult();
        return new PageResult(total,records);
    }

    @Override
    public void delete(Long id) {
        mobileLinkMapper.delete(id);
    }

    @Override
    public MobileLinkVO selectById(Long id) {
        MobileLinkVO mobileLinkVO = mobileLinkMapper.selectById(id);
        return mobileLinkVO;
    }
}
